<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use App\Jobs\VideoShortUrl;
use App\Lib\ImgCompressor;
use App\Lib\Kuaidi100;
use Carbon\Carbon;
use GifCreator\GifCreator;
//use Intervention\Gif\Encoder;
use Gouguoyin\EasyHttp\Http;
use Intervention\Gif\Decoded;
use Intervention\Image\Facades\Image;
use Intervention\Gif\Encoder as Encoder;

class TestController extends BaseController
{

    public function test() {
        $disk = \Storage::disk('qiniu');
        $disk->put('abcde.mp4', file_get_contents('aaa.mp4'));
        exit;
        $appid='ttbf22c99f20186d6c';
        $secret="168d82e6513b3af90c73c965edec59ff66db6fed";

        $url="https://developer.toutiao.com/api/apps/token?appid=".$appid."&secret=".$secret."&grant_type=client_credential";
        $html = file_get_contents($url);  //访问网址
        $obj=json_decode($html,true);
        $access_token=$obj['access_token'];
        $imgurl = $_POST['imgurl'];

        $postHeader=array("X-Token:".$access_token."");

        $url = 'https://developer.toutiao.com/api/v2/tags/image/';

        $bodys=array();
        $bodys['targets']=array(
            'ad', 'porn', 'politics', 'disgusting'
        );
        $bodys['tasks']=array(
            array('image'=>$imgurl)
        );


        $aa = Http::withHeaders([
            'X-Token' => $access_token
        ])->asJson()->post($url, $bodys)->array();
        return $aa;



        exit;
        Kuaidi100::handle([
            'com' => 'ems',
            'num' => '9862120028918'
        ]);
        exit;
        $out_trade_no = time();
        $total_amount = '0.01';
        $subject = 'test subject';
        $order = [
            'out_trade_no' => $out_trade_no,
            'total_amount' => $total_amount,
            'subject' => $subject,
        ];

        $alipay_url = $this->payApp()->app($order)->getContent();
        $app = $this->ttMini();
        $uid = 'kJxs.w-43GQ8HKPT';
        $response = $app->payment->pay($uid, $out_trade_no, $total_amount * 100, $subject, [
            'body' => 'test',
            'alipay_url' =>  $alipay_url,
            'valid_time' => '300',
            'notify_url' => 'http://beta.ling7.net/api/notify',
            'risk_info' => ''
        ]);

        return $this->success($response);
        exit;
        dispatch(new VideoShortUrl(1));
        return 11;
        exit;
        $frames = [];
        $k = 1;
        for ($i = 0;$i<=8;$i++) {
            $k = $k + 0.7;
            $aa = 'https://qiniu.huangxingle.top/2020050220384162168.mp4?vframe/jpg/w/350/offset/' . $k;
            array_push($frames, $aa);
        }

        $durations = array();
        for ($i = 0; $i <=10; $i++) {
            array_push($durations, 50);
        }

        // Initialize and create the GIF !
        $gc = new GifCreator();
        $gc->create($frames, $durations, 10);

        $gifBinary = $gc->getGif();
        file_put_contents('aaa.gif', $gifBinary);
//        header('Content-type: image/gif');
//        header('Content-Disposition: filename="butterfly.gif"');
//        echo $gifBinary;
        exit;
    }

}
